<?php
require_once 'lib/controllerWithoutGetOrPost.php';
/**
 * Set a featured person and their blurb at a certain position
 *
 * @return bool
 * @param int $personId
 * @param int $position
 * @param string $blurb
 */
function setFeaturingPerson($personId, $position, $blurb)
{
    global $db;
	$queryfeaturingperson = "Select `PersonID` from FeaturingPerson where PersonID = ".$personId;
	$resultfeaturingperson = $db->query($queryfeaturingperson);	
	
	if(!empty($resultfeaturingperson)) {
		$queryupdate = "Update FeaturingPerson Set `Position` = ".$position.", `DateAdded` = '".gmdate("Y-m-j H:i:s", time() + 3600*12)."', `Blurb` = '".$blurb."' WHERE `PersonID` = ".$personId;
		$result = $db->query($queryupdate);
	} else {
		$queryinsert = "Insert Into FeaturingPerson (`PersonID`, `Position`, `DateAdded`, `Blurb`) VALUES (".$personId.",".$position.", '".gmdate("Y-m-j H:i:s", time() + 3600*12)."','".$blurb."')";
		$result = $db->query($queryinsert);
	}
    return $result === TRUE;
}
$username = $db->escape($_POST['username']);
$password = $db->escape($_POST['password']);
if($username === "amemorytree" && $password === "pass153word") {
    $personid = intval($_POST['personid']);
    $position = intval($_POST['position']);
    $blurb = $db->escape($_POST['blurb']);
    setFeaturingPerson($personid, $position, $blurb);	
} 


?>